/*
init logic (one logic one dimension)
input: 
	map_min map_max 
	v_pos 
	b_n b_unit 
output:
	b_pos b_d b_m_pos 
	map_pos map_stride count
*/
int ClipmapInit(
	int map_min, int map_max, 
	int v_pos, 
	int b_n, int b_unit			// input
	int *b_pos, int *b_d, int *b_m_pos,  // output
	int *map_pos, int *map_stride, int *count)
{
	assert(map_max > map_min);
	if (map_max <= map_min)
	{
		return -1;	
	}
	assert(v_pos >= map_min && v_pos <= map_max);	
	if (v_pos < map_min || v_pos > map_max)
	{
		return -1;	
	}
	assert(b_n * b_unit <= map_max - map_min);
	if (b_n * b_unit > map_max - map_min)
	{
		return -1;	
	}
	assert(b_n > 0);
	if (b_n <= 0)
	{
		return -1;	
	}

	int b_m = b_n / 2;

	int aligned_v_pos = map_min + (v_pos - map_min) / b_unit * b_unit;
	*b_m_pos = aligned_v_pos;
	int to_min = (aligned_v_pos - map_min) / b_unit;
	int to_max = (map_max - aligned_v_pos) / b_unit;
	if (to_min < b_m)
	{
		*b_d = to_min;
	}
	else if (to_max < b_m)
	{
		*b_d = 2 * b_m - to_max;	
	}

	*b_pos = *b_d;

	*map_pos = *b_m_pos - b_d * b_unit;
	*map_stride = b_unit;
	*count = b_n;
}

/*
move logic
intput: 
	map_min map_max 
	v_pos 
	b_n b_unit
	b_pos b_d b_m_pos
	offset 
output: b_pos b_d b_w_pos f_pos f_stride count
*/
int ClipmapMove(	map_min map_max 
	v_pos 
	b_n b_unit
	b_pos b_d b_m_pos
	offset 
output: b_pos b_d b_w_pos f_pos f_stride count)
{
}
